package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.IntegralBeliel;
import cn.stylefeng.guns.sys.modular.tao.mapper.IntegralBelielMapper;
import cn.stylefeng.guns.sys.modular.tao.model.params.IntegralBelielParam;
import cn.stylefeng.guns.sys.modular.tao.model.result.IntegralBelielResult;
import cn.stylefeng.guns.sys.modular.tao.service.IntegralBelielService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 积分比例管理表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-08-07
 */
@Service
public class IntegralBelielServiceImpl extends ServiceImpl<IntegralBelielMapper, IntegralBeliel> implements IntegralBelielService {
    @Autowired
    IntegralBelielMapper integralBelielMapper;
    @Override
    public void add(IntegralBelielParam param){
        IntegralBeliel entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(IntegralBelielParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(IntegralBelielParam param){
        IntegralBeliel oldEntity = getOldEntity(param);
        IntegralBeliel newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    /*@Override
    public void update(IntegralBeliel param) {
        return integralBelielMapper.updates(param);
    }*/

    @Override
    public IntegralBelielResult findBySpec(IntegralBelielParam param){
        return null;
    }

    @Override
    public List<IntegralBelielResult> findListBySpec(IntegralBelielParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(IntegralBelielParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public IntegralBelielParam getIntegralBelielByState() {

       return integralBelielMapper.getIntegralBelielByState();

    }

    private Serializable getKey(IntegralBelielParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private IntegralBeliel getOldEntity(IntegralBelielParam param) {
        return this.getById(getKey(param));
    }

    private IntegralBeliel getEntity(IntegralBelielParam param) {
        IntegralBeliel entity = new IntegralBeliel();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
